<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;>
<title>main</title>
    <link rel="stylesheet" type="text/css" href="http://localhost:8080/testA/arcgisjs/js/esri/css/esri.css" />

    <script type="text/javascript" src="http://localhost:8080/testA/arcgisjs/init.js"></script>
<style>
   html,body {    
            height: 100%;    
            width: 100%;    
            margin: 0;    
            padding: 0;    
       }
    #map2
    {
    	margin:50;
    	padding:0;
    }
    .button{
      padding: 3px;
      background: #eee;
      text-align: center;
      font-size: 12px;
      font-family: "微软雅黑";
    }
    .button:hover,.attr_ctrl:hover{
      background: #ccc;
      cursor: pointer;
    }
</style>

<script type="text/javascript">

require(["dojo/dom",    
         "dojo/_base/array",    
         "dojo/date/locale",    
         "dojo/parser",    
         "dijit/registry",    
      	 "esri/domUtils",    
     	 "esri/map",    
		 "esri/graphic",   
		 "esri/layers/ArcGISTiledMapServiceLayer",
         "esri/layers/ArcGISDynamicMapServiceLayer",    
         "esri/layers/FeatureLayer",
         "esri/geometry/Point",
         "esri/tasks/query",
         "esri/tasks/QueryTask",
         "esri/tasks/Geoprocessor",
         "esri/tasks/FeatureSet",
         "esri/config",   
         "esri/tasks/LinearUnit",    
         "dijit/form/DateTextBox",    
         "dijit/layout/BorderContainer",    
         "dijit/layout/ContentPane"],   
         function(dom, array, locale, parser, registry,    
        		                domUtils, Map, Graphic, ArcGISTiledMapServiceLayer,   
        		                ArcGISDynamicMapServiceLayer,    
        		                FeatureLayer, Point, Query, QueryTask ,Geoprocessor, FeatureSet,  esriConfig,LinearUnit    
        	
        		                ){
	var map;
 	var featureSet;    
    var featureLayer;    
    var query;
	var tiled= new esri.layers.ArcGISTiledMapServiceLayer("http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer");
    var dynamic=new esri.layers.ArcGISDynamicMapServiceLayer("https://yuanc.esrichina.com/arcgis/rest/services/hx/MapServer");
	map = new esri.Map(dojo.byId("map2"));
    //map.addLayer(tiled);
 	map.addLayer(dynamic);
 	map.on("load",mapOnload);
 	
 /* 	function mapQuery()
 	{
 		var draw = new esri.toolbars.Draw(map);
 	      draw.on("draw-end",addGraphicToMap);
 	      on(dom.byId("extent"), "click", function(event){
 	    	alert('OK');
 	        map.graphics.clear();
 	        map.setMapCursor("pointer");
 	        draw.activate(esri.toolbars.Draw.EXTENT);
 	      });
 	      function addGraphicToMap(evt){
 	        map.setMapCursor("default");
 	        draw.deactivate();
 	        var sfs = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,
 	          new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASHDOT,
 	             new Color([255,0,0]),
 	             2
 	          ),
 	          new Color([255,255,0,0.25])
 	        );
 	        map.graphics.add(new Graphic(evt.geometry, sfs));
 	        //根据空间进行查询
 	        var query = new Query();
 	        query.geometry = evt.geometry;
 	        featureLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(results){
 	          console.log(results);
 	          for(var i= 0,length=results.length;i<length;i++){
 	            var sms = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE,
 	              10,
 	              new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
 	                new Color([255,0,0]),
 	                1
 	              ),
 	              new Color([0,255,255,0.25])
 	            );
 	            results[i].symbol = sms;
 	            city.redraw();
 	          }
 	        });
 	        map.setExtent(evt.geometry.getExtent().expand(2));
 	      };
 	} */
 	
 	
 	
 	function mapOnClick(event)
 	{
 		try
 		{
 		var point =new esri.geometry.Point(event.mapPoint.x,event.mapPoint.y);
 		alert(JSON.stringify(point));
 		var symbol= new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 10,  
 			                     new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,  
 						         new esri.Color([255,0,0]), 1),  
 					             new esri.Color([0,255,0,0.25]));  
 		var graphic = new esri.Graphic(point,symbol);
 		var gpServiceUrl = "https://yuanc.esrichina.com/arcgis/rest/services/BurstAnalysis/GPServer/Burst";
 	    var gp = new Geoprocessor(gpServiceUrl); 
 	    map.graphics.add(graphic);
 	    var features = [];  
            var g1 = new esri.Graphic(point,symbol);
            features.push(g1);
            var featureset = new esri.tasks.FeatureSet();  
            featureset.features = features;
 	    var gp = new esri.tasks.Geoprocessor(gpServiceUrl);
 	    var burstfeatureset={
 	    		 "displayFieldName": "",
 	    		 "geometryType": "esriGeometryPoint",
 	    		 "spatialReference": {
 	    		  "wkid": 4326,
 	    		  "latestWkid": 4326
 	    		 },
 	    		 "fields": [{
 	    		  "name": "OBJECTID",
 	    		  "type": "esriFieldTypeOID",
 	    		  "alias": "OBJECTID"
 	    		 }],
 	    		 "features": [{"geometry":{"point":[[[event.mapPoint.x,event.mapPoint.y]]]}}],
 	    		 "exceededTransferLimit": false
 	    		};
 	    var params={
 	    		Burst:burstfeatureset
 	    };
 		gp.submitJob(params, gpJobComplete, gpJobStatus, gpJobFailed);
 		}catch(error)
 		{
 			alert(error.message);
 		}
 	}
 	
 	
 	function jobResult(result) {  
 	    var jobId = result.jobId;  
 		    var status = result.jobStatus;  
 		    if(status === esri.tasks.JobInfo.STATUS_SUCCEEDED) {  
 		        //成功之后，将其中的结果取出来，当然这也是参数名字。  
 		        //在模型中，想要取出中间结果，需要设置为模型参数  
 		        //gp.getResultData(jobId, "output", addResults);  
 		    }
 		}  
 	function mapOnload()
 	{
 		map.on("click",mapOnClick);
 	}
 	
    function findHotspot() {
 		//map.on("click",mapOnClick);
      /*   query = new Query();    
        featureLayer = new FeatureLayer("http://192.168.0.248:6080/arcgis/rest/services/guanx/guanx/MapServer/1");    
        query.returnGeometry = true;    
        query.outFields = ["*"];    
        query.where = "1=1";    
        featureLayer.queryFeatures(query, function (fs) {    
            featureSet = fs;    
           var gp = new Geoprocessor(gpServiceUrl);    
           var vsDistance = new LinearUnit();    
           vsDistance.distance = 50000;    
          //该单位根据GP发布的单位进行选择    
           vsDistance.units = "esriFeet";    
           //设置GP参数    
           var params = {    
              SDE_subway: featureSet,    
                Expression: buildDefinitionQuery(),    
                Distance__value_or_field_: vsDistance    

          };    
           //cleanup any results from previous runs    
           cleanup();    
          gp.submitJob(params, gpJobComplete, gpJobStatus, gpJobFailed);    
        }); */
   }
 	
    //GP完成之后加载结果图层    
    function gpJobComplete(jobinfo) {   
    	
    	  alert(jobinfo.jobId);
/*          //construct the result map service url using the id from jobinfo we'll add a new layer to the map    
         var mapurl = mapserviceurl + "/" + jobinfo.jobId;    
         var hotspotLayer = new ArcGISDynamicMapServiceLayer(mapurl, {    
            "id": "bufferlayer"    
         });    

        //add the hotspot layer to the map    
        map.addLayers([hotspotLayer]); */
        
        
    }    
    //获得GP运行状态    
    function gpJobStatus(jobinfo) {    
        //domUtils.show(dom.byId('status'));    
         var jobstatus = '';    
        switch (jobinfo.jobStatus) {    
            case 'esriJobSubmitted':    
                 jobstatus = 'Submitted...';    
               break;    
           case 'esriJobExecuting':    
                 jobstatus = 'Executing...';    
                break;    
             case 'esriJobFailed':    
                jobstatus = 'Failed...';    
                 break;    
            case 'esriJobSucceeded':  
            	jobstatus = 'Succeeded...'
                 //domUtils.hide(dom.byId('status'));    
                 break;    
         }    
         //dom.byId('status').innerHTML = jobstatus;
         alert(jobstatus);
     }    
     //获得GP失败信息    
    function gpJobFailed(error) {   
    	//alert("gp:error"+error);
        //dom.byId('status').innerHTML = error;    
        //domUtils.hide(dom.byId('status'));    
    }
});

</script>     
</head>
<body class="tundra">
 <div id="map2" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'center'" style="position:relative;width:100%; height:100%; border:1px solid #000;"></div>
</body>
</html>